adding upsertWithWhere - #2539
Conversation
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
Can one of the admins verify this patch? |
3 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
We are still working on adding tests to this PR. |
|
Changes to test files have been made for upsertWithWhere. Pls review. |
| description: 'An object of model property name/value pairs' }, | ||
| ], | ||
| returns: { arg: 'data', type: typeName, root: true }, | ||
| http: { verb: 'put', path: '/upsertWithWhere' }, |
There was a problem hiding this comment.
I think we usually use POST for non-root endpoints like /upsertWithWhere.
Alternatively, we can use PATCH to be consistent with upsert that's mapped to PATCH / by default since LB 3.0.
There was a problem hiding this comment.
@bajtos Could you please confirm me that since this is a new method which is being introduced we don't need to make it configurable like the way we did with replaceOnPUT flag for replaceOrCreate/updateOrCreate and replaceById/patchAttributes, right?
There was a problem hiding this comment.
@bajtos ping Please see ^ Also please let @mountain1234585 know whether they should go for POST /updateOrCreate or PATCH /updateOrCreate? I have no strong opinion in this regard.
CC: @raymondfeng
There was a problem hiding this comment.
Could you please confirm me that since this is a new method which is being introduced we don't need to make it configurable like the way we did with replaceOnPUT flag for replaceOrCreate/updateOrCreate and replaceById/patchAttributes, right?
Yes, no need to make this configurable.
whether they should go for POST /updateOrCreate or PATCH /updateOrCreate? I have no strong opinion in this regard.
Let's go with POST /upsertWithWhere or even POST /updateOrCreateWithWhere.
There was a problem hiding this comment.
@mountain1234585 Lets got for POST /upsertWithWhere and please make sure you add enough test coverage; please look into PR#2316 which gives you an idea what test coverage should be added in this patch.
|
@slnode ok to test |
|
@mountain1234585 thank you for the pull request, it looks mostly good to me. I'll let @Amir-61 to lead the review and give this the final approval. |
|
I guess this patch is missing lots of test cases; at least tests in |
|
I see some commit-linter issues: Also you PR needs to be rebased on top of master. Last but not least I see all of tests fail. Please look into failures and make sure they all pass. Thanks |
|
@Amir-61 While I was running the tests in model.test.js and remoting.integration.js as is without adding any additional tests, there were many failures I could see. I am running mocha test/remoting.integration.js and mocha test/model.test.js in loopback directory. Please let me know , if I am missing out on configuring . I could do a clean run for access-control.integration.js. |
|
Was able to run the tests using npm test. |
You need to rebase all your commits on top of master and I believe the failures have been solved in the latest commits |
f333a37 to
4faf41a
Compare
|
@Amir-61 I have squashed all commits into one and rebased on top of master. |
|
@rmg I'm looking into failures; however the logs does not give that much info why tests fail. One of the logs is here. Can you find the reason why tests fail which may help @mountain1234585 to resolve it and get this patch pass our CI? |
| * @param {Error} err Error object; see [Error object](http://docs.strongloop.com/display/LB/Error+object). | ||
| * @param {Object} model Updated model instance. | ||
| */ | ||
|
|
There was a problem hiding this comment.
remove one extra space in front of =
There was a problem hiding this comment.
You can also align them together like:
PersistedModel.patchOrCreateWithWhere =
PersistedModel.upsertWithWhere = function upsertWithWhere(...) {
});
|
@Amir-61 @superkhau |
| }); | ||
| }); | ||
| }); | ||
| lt.beforeEach.givenModel('accountWithReplaceOnPUTtrue'); |
There was a problem hiding this comment.
accountWithReplaceOnPUTtrue is added specifically for testing replace methods when replaceOnPUT flag is set to true; I don't think you should test with that model; I believe you should test it with account model instead to make the purpose of test clear.
There was a problem hiding this comment.
@bajtos Should I create a new model called account under test/fixtures/common/models .
I see in test/fixtures/common/models, there is already account.json and inside which the "name" is specified as "accountWithReplaceOnPUTtrue" and plural as "accounts-replacing". Please let me know. For now, I have deleted this block, since I have already added tests for "users" model and "banks" model respectively :
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', '/api/users/upsertWithWhere');
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', '/api/users/upsertWithWhere');
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', '/api/users/upsertWithWhere');
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', '/api/banks/upsertWithWhere');
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', '/api/banks/upsertWithWhere');
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', '/api/banks/upsertWithWhere');
There was a problem hiding this comment.
there is already account.json and inside which the "name" is specified as "accountWithReplaceOnPUTtrue" and plural as "accounts-replacing".
Oh right; by default LoopBack 3.0 sets replaceOnPUT to true, whereas in LoopBack 2.x it is set to false by default; so that's why account.json has a name property accountWithReplaceOnPUTtrue. How about using other available models in test/fixtures/access-control/common/models; probably you can use bank model for instance. I do not have a strong opinion I leave it to you and @bajtos.
|
Regarding your question in 2359-comment, it seems in the example code you posted you are using I'm busy with landing your 2.x backporting beside other tasks/responsibilities that I have; I sent PR-1061 which implements |
| 'deleteById(id:any):object DELETE /stores/:id', | ||
| 'count(where:object):number GET /stores/count', | ||
| 'prototype.patchAttributes(data:object):store PATCH /stores/:id', | ||
| 'createChangeStream(options:object):ReadableStream POST /stores/change-stream', |
There was a problem hiding this comment.
Please move this test to describe('Model shared classes', (the block which starts on line 76) and assert only on the methods related to your patch.
it('has upsertWithWhere remote method', function() {
var storeClass = findClass('store');
var methods = getFormattedMethodsExcludingRelations(storeClass.methods);
var expectedMethods = [
'upsertWithWhere(where:object,data:object):store POST /stores/upsertWithWhere',
];
expect(methods).to.include.members(expectedMethods);
});|
I quickly reviewed the patch, the code looks mostly good. As I see it, there are three line comments above to address, and then the missing test for ACL and |
|
@bajtos I tried adding lt.it.shouldBeAllowed under the block lt.describe.whenLoggedInAsUser(starting at line 96) in the describe('/users', function() {} block. But it failed with 404. |
d75f8e9 to
fda002c
Compare
It gives 401; You have already added: TBH I'm not sure why; @bajtos could you please help @mountain1234585 with this? Thanks! PS: @mountain1234585 Please when copy&paste code put them in the code-block |
|
@mountain1234585 please commit your code to github, so that I can run your failing unit test locally on my machine. Also please rebase your patch on top of the current master. |
fda002c to
9eed018
Compare
|
@bajtos Also , I noticed in the recent builds one test case ( not relevant to upsertWithWhere feature is failing). |
Oh, I see it now. Upsert does not support We should follow We should eventually find a way how to fix I am proposing to revert the changes in |
9eed018 to
aef6dca
Compare
|
@bajtos I have made the changes as you have suggested and committed the changes. PTAL. |
|
The patch LGTM in general. I'll leave the final approval to @Amir-61, he has better understanding of the overall context of this work. |
|
@slnode test please |
1 similar comment
|
@slnode test please |
|
@slnode test please |
|
@Amir-61 the failing build seems to have been cleared already, but since it is PhantomJS + Windows, I imagine it was probably related to running out of handles again. The VMs were recently rebooted, so that will hopefully give us another few days without those errors coming back. |
|
Landed. Thanks for the contribution! |
Requires loopbackio/loopback-datasource-juggler#1001